﻿$(function () {
    switch ($('#ModuleID').val()) {
        case '1':
            switch ($('#BrokerageTypeID').val()) {
                case 1:
                case 2:
                    if (isAuthority('141')) {
                        $('#addbtn').show();
                    }
                    else {
                        $('#addbtn').hide();
                    }
                    break;
                case 3:
                case 4:
                case 5:
                    if (isAuthority('142')) {
                        $('#addbtn').show();
                    }
                    else {
                        $('#addbtn').hide();
                    }
                    break;
                default:

            }
            break
        case '4':
            switch ($('#BrokerageTypeID').val()) {
                case 9:
                    if (isAuthority('256')) {
                        $('#addbtn').show();
                    }
                    else {
                        $('#addbtn').hide();
                    }
                    break;
                case 10:
                case 11:
                    if (isAuthority('257')) {
                        $('#addbtn').show();
                    }
                    else {
                        $('#addbtn').hide();
                    }
                    break;
                default:

            }
            break
        default:

    }
    initTable();
    //$table.bootstrapTable('hideColumn', 'optionStr');
});
var $table = $('#table');
function initTable() {
    $table.bootstrapTable({
        url: '/Account/Brokerage/BrokerageGroupLevelListAsync',            //数据来源地址
        method: 'post',                     //数据请求方式
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: false,                   //是否启用分页
        sidePagination: 'server',           //在服务器端分页
        queryParams: queryParams,           //传递参数
        pageNumber: 1,                      //初始化加载第一页，默认第一页
        pageSize: 20,                       //每页的记录行数（*）
        pageList: [10, 20, 30, 40, 50],     //可供选择的每页的行数（*）
        clickToSelect: true,                //是否启用点击选中行
        //toolbar: "#tableToolBar",
        height: getHeight(),
        search: true,
        showRefresh: true,
        showColumns: true,
        toolbar: '#exampleToolbar',
        iconSize: 'outline',
        icons: {
            refresh: 'glyphicon-repeat',
            columns: 'glyphicon-list'
        },
        toolbar: '#exampleToolbar',
        columns: [{
            width: 38,
            field: 'aaaaaaa',
            checkbox: true,
            visible: false,
        }, {
            title: '编号',
            align: 'center',
            field: 'id',
            visible: false,
        }, {
            title: '业绩',
            align: 'center',
            field: 'achievement',
        }, {
            field: 'percentage',
            title: '提成',
            align: 'center',
        }, {
            field: 'award',
            title: '奖金',
            align: 'center',
        }, {
            field: 'a',
            title: '删除',
            align: 'center',
            formatter: function (value, row, index) {
                var a= '<a onClick="del(' + $('#ModuleID').val() + ',' + row.id + ')" href="javascript:void(0)">' +
                    ' <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>' +
                    '</a> ';
                switch ($('#ModuleID').val()) {
                    case '1':
                        switch ($('#BrokerageTypeID').val()) {
                            case '1':
                            case '2':
                                if (isAuthority('141')) {
                                    return a;
                                }
                                break;
                            case '3':
                            case '4':
                            case '5':
                                if (isAuthority('142')) {
                                    return a;
                                }
                                break;
                            default:

                        }
                        break
                    case '4':
                        switch ($('#BrokerageTypeID').val()) {
                            case '9':
                                if (isAuthority('256')) {
                                    return a;
                                }
                                break;
                            case '10':
                            case '11':
                                if (isAuthority('257')) {
                                    return a;
                                }
                                break;
                            default:

                        }
                        break
                    default:

                }
                return '';
            }
        }
        ]
    });
}



//查询的参数
var queryParams = function (params) {
    var temp = {
        ModuleID: $('#ModuleID').val(),
        BrokerageGroupID: $('#BrokerageGroupID').val(),
        BrokerageTypeID: $('#BrokerageTypeID').val(),
    };
    return temp;
};




function show(id) {
    $('#BrokerageTypeID').val(id);
    $('.T').attr('class', 'btn btn-white T');
    $('#T' + id).attr('class', 'btn btn-primary T');
    refreshTable();
}

//获取表格高度
function getHeight() {
    return $(window).height() - 150;
};
//刷新表格数据
var refreshTable = function () {
    $table.bootstrapTable('refresh');
};
//插入按钮
$('#addbtn').click(function (e) {
    parent.layer.open({
        type: 2,
        title: '添加佣金分组等级',
        shadeClose: false,
        shade: 0.4,
        area: ['600px', '500px'],
        content: '/Account/Brokerage/AddBrokerageGroupLevel?ModuleID=' + $('#ModuleID').val() + '&BrokerageGroupID=' + $('#BrokerageGroupID').val() + '&BrokerageTypeID=' + $('#BrokerageTypeID').val(),//?depid=' + $('#depart_id').val(),//$.getUrlParam('id'),// 
        end: function () {
            refreshTable();
        }
    });
});
$('#returnbtn').click(function (e) {
    window.history.back(-1);
});
function del(ModuleID, ID) {

    layer.confirm('您确定要删除吗？', {
        btn: ['是的', '取消'] //按钮
    }, function () {
        $.ajax({
            url: '/Account/Brokerage/DelBrokerageGroupLevel',
            type: "post",
            dataType: "json",
            data: { ID: ID, ModuleID: $('#ModuleID').val() },
            success: function (data) {
                //Info,Success,Warning,Error
                var type = data.type;
                if (type == 1) {
                    layer.msg(data.content,
                        {
                            icon: 6, time: 2000
                        },
                        function () {
                            refreshTable();
                        });
                } else {
                    layer.msg(data.content, { icon: 5, time: 2000 });
                }
            }
        });
    }, function () {
        return;
    });

}
